var express = require('express');
var router = express.Router();

const admin = require("../sql/admin");
const sql = require("../sql/sql");
const md5 = require("md5");
// const session = require("express-session");

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('login');
});
router.post('/guard', function(req, res, next) {
    // res.send(req.body)
    sql.getData(admin,{ 
        userName:req.body.un,//品牌
        PassWord:md5(req.body.pw),}).then((data)=>{
            if(data.length>0){
                // res.send("Ok");
                // res.send(data[0].power);
                req.session.isLogin = "ok";
                req.session.power = data[0].power;
                // console.log(req.session.powre)
                res.redirect("/");
            }else{
                // res.send("No");
                req.session.isLogin='';
                res.redirect("/login");
            }
        })
//   res.render('login');
});

module.exports = router;